package com.leoandroid.tool.toolsbox;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import androidx.appcompat.app.AppCompatActivity;

import com.leoandroid.tool.toolsbox.dialog.ProtocolDialog;
import com.leoandroid.tool.toolsbox.largeread.R;
import com.leoandroid.tool.toolsbox.largeread.activity.ToolsMainActivity;
import com.leoandroid.tool.toolsbox.largeread.utils.SPUtil;
import com.leoandroid.tool.toolsbox.largeread.utils.StatusBarUtil;
import com.leoandroid.tool.toolsbox.largeread.utils.ToolUtils;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        ToolUtils.setStatusBarHomeTransparent(this);
        StatusBarUtil.setLightMode(this);

        boolean isAgressment = SPUtil.with(this).load().read("isAgressment", false);
        if (!isAgressment){
            showProtocolDialog();
        }else{
            toMain();
        }
    }

    private void showProtocolDialog(){
        ProtocolDialog protocolDialog = new ProtocolDialog(this,R.style.dialog);
        protocolDialog.show();
        protocolDialog.setOnProtocolDialogListener(new ProtocolDialog.OnProtocolDialogListener() {
            @Override
            public void agree() {
                SPUtil.with(SplashActivity.this).load().save("isAgressment",true);
                toMain();
            }

            @Override
            public void refuse() {
                finish();
            }
        });
    }

    private void toMain(){
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(SplashActivity.this, ToolsMainActivity.class);
                startActivity(intent);
                finish();
            }
        },1500);


    }
}